package com.ctf.soft.ms.utils;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

/**
 * 描述：获取对象某个属性的注解值
 * 最近修改时间：2015/8/27 11:22
 *
 * @author DWZ
 * @since 2015/8/27 10:09
 */


public class AnnotationUtil {

    /**
     * 获取desClass对象property域的annClass注解的name属性
     *
     * @param desClass 目标对象class
     * @param annClass 注解class
     * @param property 要获取的域
     * @param name     注解的属性名
     * @return 属性值
     * @author dwz
     */
    public static String getColumnValue(Class desClass, Class annClass, String property, String name) {
        String value = "";
        try {
            Annotation s = desClass.getDeclaredField(property).getAnnotation(annClass);
            Method method = s.getClass().getDeclaredMethod(name);
            value = (String) method.invoke(s);
        } catch (Exception e) {
            System.out.println("获取注解失败,ERROR========>");
            System.out.println(e.getMessage());
        }
        return value;
    }
}

